<template>
  <div id="app">
    <router-view />
    <theme-picker />
  </div>
</template>

<script>
import ThemePicker from "@/components/ThemePicker";
import { mapGetters } from "vuex";

export default {
  name: "App",
  components: { ThemePicker },
  computed: {
    ...mapGetters(["sidebar"]),
  },
  watch: {
    // 使用$routr监听，to: 去到的页面 from: 顾名思义 指的是从哪个页面过来, 下面有2种方法
    $route (to, from) {
      if (!this.sidebar.opened) {
        this.$store.dispatch("app/toggleSideBar");
      }
    }
  },
  metaInfo () {
    if (this.sidebar) {
      if (!this.sidebar.opened) {
        this.$store.dispatch('app/toggleSideBar')
      }

    }
    return {
      title: this.$store.state.settings.dynamicTitle && this.$store.state.settings.title,
      titleTemplate: title => {
        return title ? `${title} - ${process.env.VUE_APP_TITLE}` : process.env.VUE_APP_TITLE
      }
    }
  }
};
</script>
<style scoped>
#app .theme-picker {
  display: none;
}
</style>
